<template>
  <div class="top_bar">
    <div class="banner2 category">
      <div
        class="banner2_item"
        :class="{ red: activeIndex == 0 }"
        @click="smzq"
      >
        首页
      </div>
      <div class="banner2_item" :class="{ red: activeIndex == 2 }" @click="nvz">
        旅行分享
      </div>
      <div class="banner2_item" :class="{ red: activeIndex == 3 }" @click="mz">
        景点推荐
      </div>
      <div
        class="banner2_item"
        :class="{ red: activeIndex == 4 }"
        @click="sxsg"
      >
        限时特惠
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {};
  },
  watch: {},
  computed: {
    activeIndex() {
      let index = this.getCookie('activeIndex');
      if(this.$store.state.bannerIndex){
        return this.$store.state.bannerIndex
      }else{
        return index;
      }
    },
  },
  methods: {
    getCookie(name) {
      let matches = document.cookie.match(
        new RegExp(
          "(?:^|; )" +
            name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, "\\$1") +
            "=([^;]*)"
        )
      );
      return matches ? decodeURIComponent(matches[1]) : undefined;
    },
    smzq() {
      this.$store.commit("setBanner", 0);
      this.$root.$router.push("/");
      document.cookie = "activeIndex=" + 0;
    },
    nz() {
      this.$store.commit("setBanner", 1);
      this.$root.$router.push("/zxjd");
      document.cookie = "activeIndex=" + 1;
    },
    nvz() {
      this.$store.commit("setBanner", 2);
      this.$root.$router.push("/share");
      document.cookie = "activeIndex=" + 2;
    },
    mz() {
      this.$store.commit("setBanner", 3);
      this.$root.$router.push("/djgl");
      document.cookie = "activeIndex=" + 3;
    },
    sxsg() {
      this.$store.commit("setBanner", 4);
      this.$root.$router.push("/xsth");
      document.cookie = "activeIndex=" + 4;
    },
  },
  created() {},
  mounted() {},
};
</script>
<style scoped lang="less">
.top_bar {
  z-index: 1000;
  position: fixed;
  top: 0;
  width: 100%;
  height: 68px;
  padding: 8px 20px;
  background-color: transparent;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.8);
  .category {
    width: 800px;
    .banner2_item {
      cursor: pointer;
      font-size: 16px;
      font-weight: 600;
      color: black;
    }
    .banner2_item:hover {
      color: rgb(255, 128, 0);
    }
  }
  .banner2 {
    display: flex;
    height: 100%;
    align-items: center;
    justify-content: space-around;
  }
  .account_edit {
    .profile {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      white-space: nowrap;
      line-height: 40px;
      text-align: center;
      background-color: #f7f1e3;
      font-size: 12px;
      color: fff;
    }
    width: 350px;
    .sign_off {
      width: 180px;
      display: flex;
      justify-content: space-around;
    }
    .sign_in {
      width: 220px;
      display: flex;
      justify-content: space-around;
    }
  }
}
.sign_in_width {
  width: 280px !important;
}
.red {
  color: rgb(255, 128, 0) !important;
  font-weight: bold !important;
}
</style>